"""
this module deal with the structure naming part

the first thing is to figure out the meaning of each part

"""
from Lyric import Lyric
from LyricSA import analysis,analysis1,printseg,analysis2
curanalysis = analysis2

def RUStructName(l,segs):
    """
    analysis the structure of the song
    a) the first paragraph is the verse
    b) if the last segment is less than three sentense, it's ending ,the seg befor this is  chorus
    c) if the last segment is greater than three sentense, it's chorus
    d) the seg with the same first line with the chorus identified above are chorus
    e) all the other are verse
    f) the part from 0 to the first sentence are introduction

    problems:
    1) the ending may have more than 3 sentences
    2) the structure is more than verse and chorus
    """
    lines = l.getlinelist()

    segstype = []#verse,chorus,ending,unknown
    for s in segs:
        segstype.append("unknown")
    segstype[0] = "verse"

    chorusfirstline = ""
    if segs[-1][1]-segs[-1][0]+1 <=3:
        segstype[-1] = "ending"
        chorusfirstline = lines[segs[-2][0]]['content']
    else:
        chorusfirstline = lines[segs[-1][0]]['content']
    
    print "thefirstline:"+chorusfirstline

    for i in range(len(segs)):
        if lines[segs[i][0]]['content'] == chorusfirstline:
            segstype[i] = "chorus"

    return segstype

if __name__ == "__main__":
    l = Lyric()
    #fname = "harrybobo.lrc"
    fname = "wangfei.txt"
    l.loadfile(fname)
    linelist = l.getlinelist()

    segs = curanalysis(l)
    printseg(linelist,segs)

    print RUStructName(l,segs)
